<%-- 
    Document   : SearchFlower
    Created on : Nov 3, 2012, 3:13:11 PM
    Author     : ADMIN
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
   "http://www.w3.org/TR/html4/loose.dtd">
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>
<%@page import="DAO.CategoryListDAO"%>
<jsp:useBean id="category" class="DAO.CategoryListDAO"/>
<% category.CategoryListtoXML(getServletContext().getRealPath("/"));%>

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <title>Index</title>
        <link href="Style.css" rel="stylesheet" type="text/css" />
        <script src="scrip/jquery-1.4.4.min.js" type="text/javascript"></script>
        <link href=""
    </head>

    <body >
        <script type="text/javascript">


            $(function () {

                $('a').click(function () {
                    $('a.active').removeClass('active'); // remove the class from the currently selected
                    $(this).addClass('active'); // add the class to the newly clicked link
                });
            });


            function loadXML(dname)
            {
                try
                  {
                      xhttp=new XMLHttpRequest();
                  } catch(e) {
                    try{
                             xhttp=new ActiveXObject("Msxml2.XMLHTTP");
                    } catch(e){
                        xhttp=new ActiveXObject("Microsoft.XMLHTTP");
                    }
                }
                xhttp.open("GET",dname,false);
                xhttp.send(null);
                return xhttp.responseXML;
            }



            function SearchFlower(categoryId){
                var xmlSearchHttp = null;
                try {
                    xmlSearchHttp = XMLHttpRequest();
                }catch(e){
                    try{
                        xmlSearchHttp = new ActiveXObject("Msxml2.XMLHTTP");
                    }
                    catch(e){
                        xmlSearchHttp = new ActiveXObject("Microsoft.XMLHTTP");
                    }
                }
                if(xmlSearchHttp==null){
                    alert("Your browser does not support AJAX!")
                    return;
                }
                try{
                    var url= "SearchFlower?action=SearchByCategory&id="+categoryId;
                    xmlSearchHttp.open("GET",url,true);
                    xmlSearchHttp.send(null);
                    xmlSearchHttp.onreadystatechange = function()
                    {
                        if(xmlSearchHttp.readyState==4 && xmlSearchHttp.status==200){
                            // lay response text
                            var response = xmlSearchHttp.responseText;
                            if(response =='Success') {
                                var xmlurl = '${pageContext.request.contextPath}' + "/XML/FlowerCategory"+categoryId+".xml";
                                var  xml = loadXML(xmlurl);
                                var xslurl = '${pageContext.request.contextPath}' +"/XSL/FlowerCategory.xsl";
                                var  xsl = loadXML(xslurl);
                                displayResult(xml, xsl, 'list-flower');
                            }
                        }
                    }
                }catch(e){
                    alert("error: "+ e);
                }
            }

            function displayResult(xml, xsl, divId) {
                if (window.ActiveXObject) {
                    var out = xml.transformNode(xsl);
                    document.getElementById(divId).innerHTML = out;
                } else {
                    var xsltProcessor = new XSLTProcessor();
                    xsltProcessor.importStylesheet(xsl);
                    resultDocument = xsltProcessor.transformToFragment(xml, document);
                    document.getElementById(divId).innerHTML="";
                    document.getElementById(divId).appendChild(resultDocument);
                }

            }








        </script>
        <div id="Wrapper">
            <div id="Header">
                <div id="Hd-Top">
                    <div class="Logo">
                    </div><!--End Logo-->
                    <div id="Hd-Top-Right">
                        <div id="shoping-cart">
                            <p><strong>Shopping Cart:</strong> Now in your cart <strong>0 Items</strong></p>
                        </div><!--End shopping-cart-->
                        <c:choose>
                            <c:when test="${empty sessionScope.USER}">
                                <div id="Login-form">
                                    <form method="POST" action="Controller">
                                        <input id="Txt-Username" name="Txt-Username" type="text" placeholder="Tài khoản"/>
                                        <input id="Txt-Password" name="Txt-Password" type="password" placeholder="Mật khẩu"/>
                                        <input class="btn-Login" type="submit" value="Login" name="action"/>
                                    </form>
                                    <a class="ForgotPw" href="">Quên mật khẩu?</a>
                                    <p>|</p>
                                    <a class="LinkRegister" href="Register.jsp">Đăng ký?</a>
                                </div><!--End Login-form-->
                            </c:when>
                            <c:otherwise>
                                <div id="Login-form">
                                    Welcome: ${sessionScope.USER.username}
                                </div>
                            </c:otherwise>
                        </c:choose>

                    </div><!--End Hd-Top-Right-->
                </div><!--End Hd-Top-->
                <div id="Hd-Menu">
                    <ul class="Menu">
                        <li><a href="index.jsp">Trang chủ</a>|</li>
                        <li><a>Sản phẩm mới</a>|</li>
                        <li><a>Sản phẩm đặc biệt</a>|</li>
                        <li><a>Hướng dẫn mua hàng</a>|</li>
                        <li><a>Liên hệ</a></li>
                    </ul>
                    <div id="Search">
                        <p>Tìm kiếm:</p>
                        <form method="post" action="SearchFlower">
                            <input id="keyword" type="text" name="Txt-Search" placeholder="Nhập từ khóa để tìm kiếm" />
                            <input id="btnsearch" type="submit" value="SeachByName" name="action"/>
                        </form>
                    </div><!--End Search-->
                </div><!--End Hd-Menu-->
                <div id="Hd-Bottom">
                    <div class="box-image1">
                    </div><!--End box-image-->
                    <div class="box-image2">
                    </div><!--End box-image-->
                    <div class="box-image3">
                    </div><!--End box-image-->
                </div><!--End Hd-Bottom-->
            </div><!--End Header-->
            <div id="Body">
                <div id="Category">
                    <p>Danh mục sản phẩm</p>
                    <c:import charEncoding="UTF-8" url="XML/CategoryList.xml" var="xmldoc"/>
                    <c:import charEncoding="UTF-8" url="XSL/CategoryList.xsl" var="xsldoc"/>
                    <x:transform xml="${xmldoc}" xslt="${xsldoc}" />
                </div><!--End Catergory-->               

                <div id="list-flower">
                    <c:set var="info" value="${requestScope.INFO}"/>
                    <c:if test="${not empty info}">
                        <c:forEach var="row" items="${info}">
                            <div class="box-product">
                                <div id="img-product">
                                    <img src="${row.image}"/>
                                </div><!--End img-product-->
                                <p class="name-product">${row.productName}</p>
                                <p class="price">${row.price}</p>
                                <input class="btn-addcart" type="submit" value="" />
                                <a class="detail" href="">Detail</a>
                            </div><!--End box-product-->
                        </c:forEach>
                    </c:if>
                </div>
                    <!--End list-product-->
            </div><!--End Body-->
            <div id="Fotter">
                <p>@FPT-University XML Chicken Group</p>
            </div><!--End Fotter-->
        </div><!--End Wrapper-->
    </body>
</html>
    